/* GUI CONVERTED from rcsomtb.p (converter v1.76) Thu Sep  5 09:20:48 2002 */
/* rcsomtb.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.27.2.18 $                                                    */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 7.3      LAST MODIFIED: 09/30/92   BY: WUG *G462*               */
/* REVISION: 7.3      LAST MODIFIED: 01/26/93   BY: bcm *G429*               */
/* REVISION: 7.3      LAST MODIFIED: 05/24/93   BY: WUG *GB29*               */
/* REVISION: 7.3      LAST MODIFIED: 06/01/93   BY: WUG *GB46*               */
/* REVISION: 7.3      LAST MODIFIED: 07/07/93   BY: WUG *GD20*               */
/* REVISION: 7.3      LAST MODIFIED: 07/07/93   BY: WUG *GD22*               */
/* REVISION: 7.3      LAST MODIFIED: 08/13/93   BY: WUG *GE19*               */
/* REVISION: 7.4      LAST MODIFIED: 08/12/93   BY: bcm *H064*               */
/* REVISION: 7.4      LAST MODIFIED: 09/21/93   BY: WUG *H130*               */
/* REVISION: 7.4      LAST MODIFIED: 09/23/93   BY: WUG *H140*               */
/* REVISION: 7.3      LAST MODIFIED: 01/20/94   BY: WUG *GI52*               */
/* REVISION: 7.4      LAST MODIFIED: 03/29/94   BY: bcm *H308*               */
/* REVISION: 7.3      LAST MODIFIED: 04/14/94   BY: WUG *GJ36*               */
/* REVISION: 7.3      LAST MODIFIED: 04/21/94   BY: WUG *GJ48*               */
/* REVISION: 7.4      LAST MODIFIED: 09/11/94   BY: rmh *GM22*               */
/* REVISION: 7.4      LAST MODIFIED: 10/15/94   BY: rxm *GN17*               */
/* REVISION: 7.4      LAST MODIFIED: 10/27/94   BY: ljm *GN62*               */
/* REVISION: 7.4      LAST MODIFIED: 11/03/94   BY: qzl *GO06*               */
/* REVISION: 7.4      LAST MODIFIED: 11/08/94   BY: ljm *GO33*               */
/* REVISION: 7.4      LAST MODIFIED: 11/30/94   BY: afs *H575*               */
/* REVISION: 7.4      LAST MODIFIED: 12/06/94   BY: jxz *GO71*               */
/* REVISION: 7.4      LAST MODIFIED: 12/15/94   BY: rxm *GN16*               */
/* REVISION: 7.4      LAST MODIFIED: 01/04/95   BY: rxm *H09P*               */
/* REVISION: 7.4      LAST MODIFIED: 03/01/95   BY: rxm *G0G5*               */
/* REVISION: 7.4      LAST MODIFIED: 04/24/95   BY: dpm *J044*               */
/* REVISION: 7.4      LAST MODIFIED: 05/23/95   by: vrn *G0NC*               */
/* REVISION: 7.3      LAST MODIFIED: 07/06/95   by: vrn *G0RV*               */
/* REVISION: 7.3      LAST MODIFIED: 08/15/95   BY: bcm *G0TB*               */
/* REVISION: 7.4      LAST MODIFIED: 12/20/95   BY: ais *G1H0*               */
/* REVISION: 7.4      LAST MODIFIED: 01/08/96   by: kjm *G1JC*               */
/* REVISION: 7.3      LAST MODIFIED: 02/02/96   BY: kjm *G1LT*               */
/* REVISION: 8.5      LAST MODIFIED: 06/07/95   BY: gwm *J049*               */
/* REVISION: 8.5      LAST MODIFIED: 05/14/96   BY: vrn *G1LV*               */
/* REVISION: 8.5      LAST MODIFIED: 07/19/96   BY: *G29C* Ajit Deodhar      */
/* REVISION: 8.5      LAST MODIFIED: 10/15/96   BY: *G2GJ* Ajit Deodhar      */
/* REVISION: 8.5      LAST MODIFIED: 10/29/96   BY: *G2H6* Suresh Nayak      */
/* REVISION: 8.5      LAST MODIFIED: 02/20/97   BY: *H0SJ* Suresh Nayak      */
/* REVISION: 8.5      LAST MODIFIED: 05/08/97   BY: *J1QW* Suresh Nayak      */
/* REVISION: 8.5      LAST MODIFIED: 06/16/97   BY: *J1T5* Suresh Nayak      */
/* REVISION: 8.5      LAST MODIFIED: 07/23/97   BY: *H1CC* Aruna Patil       */
/* REVISION: 8.5      LAST MODIFIED: 08/08/97   BY: *J1YQ* Suresh Nayak      */
/* REVISION: 8.5      LAST MODIFIED: 11/26/97   BY: *J271* Aruna Patil       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 03/24/98   BY: *J2FG* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 04/22/98   BY: *J2K9* Samir Bavkar      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Bill Reckard      */
/* REVISION: 8.6E     LAST MODIFIED: 07/24/98   BY: *J2TQ* Seema Verma       */
/* REVISION: 8.6E     LAST MODIFIED: 08/31/98   BY: *J2XW* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 03/24/99   BY: *J3CP* Anup Pereira      */
/* REVISION: 8.6E     LAST MODIFIED: 08/10/99   BY: *J3K7* Surekha Joshi     */
/* REVISION: 9.1      LAST MODIFIED: 09/04/99   BY: *K22J* Ranjit Jain       */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Robin McCarthy    */
/* REVISION: 9.1      LAST MODIFIED: 01/19/00   BY: *N077* Vijaya Pakala     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 04/11/00   BY: *L0VC* Santosh Rao       */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 10/04/00   BY: *N0WD* Mudit Mehta       */
/* Revision: 1.27.2.8.2.4   BY: Katie Hilbert    DATE: 04/01/01 ECO: *P002*  */
/* Revision: 1.27.2.11      BY: Russ Witt        DATE: 06/01/01 ECO: *P00J*  */
/* Revision: 1.27.2.12      BY: Anil Sudhakaran  DATE: 07/02/01 ECO: *M1B5*  */
/* Revision: 1.27.2.13      BY: Steve Nugent     DATE: 10/15/01 ECO: *P004*  */
/* Revision: 1.27.2.14      BY: Steve Nugent     DATE: 12/14/01 ECO: *P00G*  */
/* Revision: 1.27.2.15      BY: Katie Hilbert    DATE: 04/15/02 ECO: *P03J*  */
/* Revision: 1.27.2.17     BY: Katie Hilbert    DATE: 06/10/02 ECO: *P083*  */
/* $Revision: 1.27.2.18 $  BY: Ed van de Gevel  DATE: 09/05/02 ECO: *P0HQ* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* SCHEDULED ORDER MAINT SUBPROGRAM */
{mfdeclre.i}
{cxcustom.i "RCSOMTB.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter so_recid     as recid.
define input parameter l_scx_shipto like scx_shipto no-undo.
define input parameter consignment  as logical no-undo.

define new shared variable scx_recno   as recid.
define new shared variable so_recno    as recid.
define new shared variable sod_recno   as recid.
define new shared variable global_curr as character.
define new shared variable old_site    like si_site.
define new shared variable new_site    like si_site.
define new shared variable err_stat    as integer.

define shared variable so_db           like dc_name.
define shared variable all_days        like soc_all_days.
define shared variable all_avail       like soc_all_avl.
define shared variable sotax_trl       like tax_trl.
define shared variable tax_recno       as recid.
define shared variable cmtindx         like cmt_indx.
define shared variable order-shipfrom  like scx_shipfrom no-undo.
define shared variable tax_in          like ad_tax_in.
define shared variable impexp          like mfc_logical no-undo.

define variable del-yn                 like mfc_logical  no-undo.
define variable yn                     like mfc_logical  no-undo.
define variable line                   as integer.
define variable valid_acct             like mfc_logical.
define variable save_cust_part         like cp_cust_part.
define variable counter                as integer        no-undo.
define variable ptstatus               like pt_status    no-undo.
define variable imp-okay               like mfc_logical  no-undo.
define variable newline                as integer        no-undo.
define variable shipper_found          as integer        no-undo.
define variable save_abs               like abs_par_id   no-undo.
define variable pkg_code_alt           like pt_part extent 7
                                       label "Alternate Container" no-undo.
define variable i                      as integer        no-undo.
define variable l_desc1                like pt_desc1     no-undo.
define variable l_part                 like pt_part      no-undo.
define variable l_continue             like mfc_logical  no-undo.
define variable mc-error-number        like msg_nbr      no-undo.
define variable l_conf_ship            as   integer      no-undo.
define variable l_conf_shid            like abs_par_id   no-undo.
define variable cust-resv-loc          like locc_loc     no-undo.
define variable useloc                 like mfc_logical  no-undo.
define variable l_recid1               as recid          no-undo.
define variable l_recid2               as recid          no-undo.

define shared frame so.
define shared frame so1.
define shared frame sod.
define shared frame sod1.
define shared frame sod2.

/* CONSIGNMENT VARIABLES */
define variable proc_id as character no-undo.
{socnvars.i}
using_cust_consignment = consignment.

{&RCSOMTB-P-TAG1}

{gptxcdec.i}    /* DECLARATIONS FOR gptxcval.i */

{rcordfrm.i}

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
pkg_code_alt[1]
   pkg_code_alt[2]
   pkg_code_alt[3]
   pkg_code_alt[4]
   pkg_code_alt[5]
   pkg_code_alt[6]
   pkg_code_alt[7]
 SKIP(.4)  /*GUI*/
with frame alt overlay centered side-labels attr-space
    NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-alt-title AS CHARACTER.
 F-alt-title = (getFrameTitle("ALTERNATE_CONTAINERS",29)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame alt = F-alt-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame alt =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame alt + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame alt =
  FRAME alt:HEIGHT-PIXELS - RECT-FRAME:Y in frame alt - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME alt = FRAME alt:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame alt:handle).

find first soc_ctrl no-lock no-error.
socmmts = soc_hcmmts.
if no then find first sod_det no-lock no-error.
find so_mstr where recid(so_mstr) = so_recid no-lock no-error.

assign
   so_wk_offset    = integer(substring(so_conrep,1,1))
   so_translt_days = decimal(substring(so_conrep,2,6))
   so_translt_hrs  = decimal(substring(so_conrep,8,6))
   so_cumulative   = substring(so_conrep,14,1) = "y".

find ad_mstr where ad_addr = so_ship no-lock no-error.
find cm_mstr where cm_addr = so_cust no-lock no-error.

assign
   global_site = order-shipfrom
   global_addr = l_scx_shipto.

clear frame sod no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame sod = F-sod-title.
clear frame sod1 no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame sod1 = F-sod1-title.
clear frame sod2 no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame sod2 = F-sod2-title.

{&RCSOMTB-P-TAG2}
detailloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   hide frame sod1 no-pause.
   hide frame sod2 no-pause.

   /* FIND OR CREATE DETAIL RECORD */

   save_cust_part = "".

   do with frame sod:
      prompt-for
         scx_part
         scx_po
         scx_custref
         scx_modelyr
         scx_line
      editing:

         if frame-field = "scx_part" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
               and scx_order = so_nbr
               and scx_shipfrom = order-shipfrom
               and scx_shipto = l_scx_shipto"
               scx_part "input frame sod scx_part"}

            if recno <> ? then do:
               find pt_mstr where pt_part = scx_part no-lock no-error.
               find sod_det where sod_nbr = scx_order
                  and sod_line = scx_line
               no-lock no-error.
               if available pt_mstr then
                  l_desc1 = pt_desc1.
               else
               if available sod_det then
                  l_desc1 = sod_desc.
               else
                  l_desc1 = "".

               display
                  scx_part
                  l_desc1    @ sod_desc
                  pt_um         when (available pt_mstr)
                  scx_po
                  scx_custref
                  sod_custpart  when (available sod_det)
                  scx_modelyr
                  scx_line.
            end.
         end. /* IF FRAME-FIELD = "SCX_PART" */

         /* UP AND DOWN SCROLLING FOR CUSTREF FIELD*/
         else if frame-field = "scx_custref" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
               and scx_order = so_nbr
               and scx_shipfrom = order-shipfrom
               and scx_shipto = l_scx_shipto
               and scx_part = input frame sod scx_part
               and scx_po = input frame sod scx_po"
               scx_custref "input frame sod scx_custref"}

            if recno <> ? then do:
               find pt_mstr where pt_part = scx_part no-lock no-error.
               find sod_det where sod_nbr = scx_order
                   and sod_line = scx_line
               no-lock no-error.
               if available pt_mstr then
                  l_desc1 = pt_desc1.
               else
               if available sod_det then
                  l_desc1 = sod_desc.
               else
                  l_desc1 = "".

               display
                  scx_part
                  l_desc1    @ sod_desc
                  pt_um         when (available pt_mstr)
                  scx_po
                  scx_custref
                  scx_modelyr
                  sod_custpart  when (available sod_det)
                  scx_line.
            end.
         end. /* IF FRAME-FIELD = "SCX_CUSTREF" */

         /* UP AND DOWN SCROLLING FOR MODEL YEAR FIELD*/
         else if frame-field = "scx_modelyr" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
               and scx_order = so_nbr
               and scx_shipfrom = order-shipfrom
               and scx_shipto = l_scx_shipto
               and scx_part = input frame sod scx_part
               and scx_po = input frame sod scx_po"
               scx_modelyr "input frame sod scx_modelyr"}

            if recno <> ? then do:
               find pt_mstr where pt_part = scx_part no-lock no-error.
               find sod_det where sod_nbr = scx_order
                   and sod_line = scx_line no-lock no-error.
               if available pt_mstr then
                  l_desc1 = pt_desc1.
               else
               if available sod_det then
                  l_desc1 = sod_desc.
               else
                  l_desc1 = "".

               display
                  scx_part
                  l_desc1    @ sod_desc
                  pt_um         when (available pt_mstr)
                  scx_po
                  scx_custref
                  scx_modelyr
                  sod_custpart  when (available sod_det)
                  scx_line.
            end.
         end. /* IF FRAME-FIELD = "SCX_Model Year" */

         else
         if frame-field = "scx_po" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
                 and scx_order = so_nbr
                 and scx_shipfrom = order-shipfrom
                 and scx_shipto = l_scx_shipto
                 and scx_part = input frame sod scx_part"
                     scx_po "input frame sod scx_po"}

            if recno <> ? then do:
               find pt_mstr where pt_part = scx_part no-lock no-error.
               find sod_det where sod_nbr = scx_order
                  and sod_line = scx_line no-lock no-error.
               if available pt_mstr then l_desc1 = pt_desc1.
               else if available sod_det then l_desc1 = sod_desc.
               else l_desc1 = "".

               display
                  scx_part
                  l_desc1    @ sod_desc
                  pt_um         when (available pt_mstr)
                  scx_po
                  scx_custref
                  scx_modelyr
                  sod_custpart  when (available sod_det)
                  scx_line.
            end.
         end.  /* IF FRAME-FIELD = "SCX_PO" */
         else
         if frame-field = "scx_line" then do:
            {mfnp05.i scx_ref scx_order "scx_type = 1
               and scx_order = so_nbr"
               scx_line "input frame sod scx_line"}

            if recno <> ? then do:
               find pt_mstr where pt_part = scx_part no-lock no-error.
               find sod_det where sod_nbr = scx_order
                  and sod_line = scx_line no-lock no-error.
               if available pt_mstr then l_desc1 = pt_desc1.
               else if available sod_det then l_desc1 = sod_desc.
               else l_desc1 = "".

               display
                  scx_part
                  l_desc1    @ sod_desc
                  pt_um         when (available pt_mstr)
                  scx_po
                  scx_custref
                  scx_modelyr
                  sod_custpart  when (available sod_det)
                  scx_line.
            end.
         end. /* IF FRAME-FIELD = "SCX_LINE"  */
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end. /* EDITING */

      if scx_line entered and not (scx_part entered or scx_po entered)
      then do:
         find sod_det where sod_nbr = so_nbr
            and sod_line = input frame sod scx_line
         no-lock no-error.
         if available sod_det then
            display
               sod_part @ scx_part
               sod_contr_id @ scx_po.
      end.

      if scx_line entered and
         input frame sod scx_line = 0
      then do:
         /* INVALID LINE NUMBER */
         {pxmsg.i &MSGNUM=642 &ERRORLEVEL=4}
         undo, retry.
      end. /* IF INPUT FRAME SOD SCX_LINE = 0 */

      /* LOGIC TO CORRECTLY POPULATE SCX_PART AND SCX_CUSTREF IF ONLY */
      /* SCX_PART IS ENTERED */
      if input frame sod scx_part <> "" and
         input frame sod scx_custref = ""
      then do:
         l_part  = input frame sod scx_part.
         /* SEARCH CUSTOMER ITEM/ ITEM MASTER */
         {gprun.i ""sopart.p""
            "(input l_scx_shipto,
              input """",
              input-output l_part,
              output save_cust_part)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if input frame sod scx_part = l_part then do:
            find first cp_mstr where cp_part = l_part
               and cp_cust = l_scx_shipto
            no-lock no-error.
            if available cp_mstr then do:
               l_recid1 = recid(cp_mstr).

               find last cp_mstr where cp_part = l_part
                  and cp_cust = l_scx_shipto no-lock no-error.
               if available cp_mstr then do:
                  l_recid2 = recid(cp_mstr).
                  if l_recid1 <> l_recid2 then do:
                     save_cust_part = "".
                     /* INTERNAL ITEM NUMBER CORRESPONDS TO */
                     /* MORE THAN ONE CUSTOMER ITEM */
                     /* This is an error condition if so_custref_val */
                     /* is set true. Otherwise just issue an informational */
                     /* message */
                     if so_custref_val then do:
                        {pxmsg.i &MSGNUM=5229 &ERRORLEVEL=4}
                        next-prompt scx_custref.
                        undo, retry.
                     end.
                     else do:
                        {pxmsg.i &MSGNUM=5229 &ERRORLEVEL=1}
                     end.
                  end.  /* IF L_RECID1 <> L_RECID2  */
               end. /* IF AVAILABLE CP_MSTR */
            end.  /* IF AVAILABLE CP_MSTR */
            else if not available cp_mstr and so_custref_val then do:
               /* CUSTOMER ITEM DOES NOT EXIST */
               {pxmsg.i &MSGNUM=4744 &ERRORLEVEL=4
                        &MSGARG1=getTermLabel(""CUSTOMER_ITEM"",20)}
               undo, retry.
            end.

         end.   /* IF INPUT FRAME SOD SCX_PART = L_PART */

         /* IF THE FLAG SO_CUSTREF_VAL FLAG IS YES IN SO_MSTR
            THEN DISPLAY THE CUSTOMER PART NO IN CUST REF. */
         if so_custref_val then
            display
               save_cust_part @ scx_custref.
      end.
      /* LOGIC TO CORRECTLY POPULATE SCX_PART AND SCX_CUSTREF
         IF ONLY SCX_CUSTREF IS ENTERED */
      else
      if input frame sod scx_custref <> "" and
         input frame sod scx_part = ""
      then do:
         l_part = input frame sod scx_custref.
         /* SEARCH CUSTOMER ITEM/ ITEM MASTER */
         {gprun.i ""sopart.p""
            "(input l_scx_shipto,
              input """",
              input-output l_part,
              output save_cust_part)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         find first cp_mstr where
            cp_cust_part = input scx_custref and
            cp_cust = l_scx_shipto no-lock no-error.
         if not available cp_mstr and so_custref_val then do:
            /* CUSTOMER ITEM DOES NOT EXIST */
            {pxmsg.i &MSGNUM=4744 &ERRORLEVEL=4
                     &MSGARG1=getTermLabel(""CUSTOMER_ITEM"",20)}
            undo, retry.
         end.

      end.
      /* LOGIC TO CORRECTLY POPULATE SCX_PART AND SCX_CUSTREF */
      /*IF BOTH FIELDS ARE ENTERED */
      else
      if input frame sod scx_part <> "" and
         input frame sod scx_custref <> ""
      then do:
         l_part = input frame sod scx_part.
         find cp_mstr where cp_part = l_part
            and cp_cust_part = input frame sod scx_custref
            and cp_cust = l_scx_shipto no-lock no-error.
         /* CONFIRM THAT ITEM IS AN CUSTOMER ITEM */
         if available cp_mstr then
            save_cust_part = input frame sod scx_custref.

         /* WE ONLY WANT TO CHECK IF THE CUSTOMER REFERENCE MATCHES A        */
         /* CUSTOMER ITEM, IF THE FLAG SO_CUSTREF_VAL FLAG IS SET IN SO_MSTR.*/
         if so_custref_val then do:
            if not available cp_mstr then do:
               /* NO SUCH ITEM/CUSTOMER ITEM COMBINATION FOR THIS CUSTOMER */
               {pxmsg.i &MSGNUM=8118 &ERRORLEVEL=4}
               undo, retry.
            end.
         end.
         /* FLAG EQUAL TO NO */
         else do:
            /* SEARCH CUSTOMER ITEM/ ITEM MASTER -  REPLACES ANY */
            /* CUSTOMER ITEMS WITH INTERNAL ITEM                 */
            {gprun.i ""sopart.p""
               "(input l_scx_shipto,
                 input """",
                 input-output l_part,
                 output save_cust_part)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            /* CHECK FOR DUPLICATE ENTRIES */
            if input frame sod scx_part = l_part then do:
               find first cp_mstr where cp_part = l_part
                  and cp_cust = l_scx_shipto no-lock no-error.
               if available cp_mstr then do:
                  l_recid1 = recid(cp_mstr).

                  find last cp_mstr where
                     cp_part = l_part and
                     cp_cust = l_scx_shipto
                  no-lock no-error.
                  if available cp_mstr then do:
                     l_recid2 = recid(cp_mstr).
                     if l_recid1 <> l_recid2 then do:
                        save_cust_part = "".
                        /* INTERNAL ITEM NUMBER CORRESPONDS TO MORE */
                        /* THAN ONE CUSTOMER ITEM */
                        {pxmsg.i &MSGNUM=5229 &ERRORLEVEL=1}
                     end.  /* IF L_RECID1 <> L_RECID2  */
                  end. /* IF AVAILABLE CP_MSTR */
               end.  /* IF AVAILABLE CP_MSTR */
            end.   /* IF INPUT FRAME SOD SCX_PART = L_PART */

         end.
      end.

      for first pt_mstr
         fields ( pt_desc1 pt_loc pt_part pt_pm_code pt_price
                  pt_prod_line pt_status pt_taxable pt_taxc pt_um
                  pt_ship_wt pt_ship_wt_um)
         where pt_part = l_part no-lock:
      end. /* FOR FIRST PT_MSTR */

      if not available pt_mstr then do:
         /* ITEM NUMBER DOES NOT EXIST */
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
         undo, retry.
      end. /* IF NOT AVAILABLE PT_MSTR */

      if l_part <> input frame sod scx_part then do:
         /* MAKING SURE THE OUTPUT FROM SOPART.P IS DISPLAYED */
         /* IN THE CORRECT PLACE WE ONLY WANT TO CHECK IF THE */
         /* CUSTOMER REFERENCE MATCHES A CUSTOMER ITEM IF     */
         /* THE FLAG SO_CUSTREF_VAL FLAG IS SET IN SO_MSTR.   */
         if so_custref_val then
            display save_cust_part @ scx_custref.

         /* CUSTOMER ITEM # REPLACED BY # */
         {pxmsg.i &MSGNUM=56 &ERRORLEVEL=1
                  &MSGARG1="input frame sod scx_part"
                  &MSGARG2=l_part}
         display pt_part @ scx_part with frame sod.

      end. /* IF L_PART <> SOD_PART */

      if available pt_mstr then l_desc1 = pt_desc1.
      else if available sod_det then l_desc1 = sod_desc.
      else l_desc1 = "".

      /*  CHECK TO SEE WHETHER THE PART IS RESTRICTED FROM THE
          BEING USED IN A SO - CODE COPIED FROM sosomta.p. */
      assign
         ptstatus = pt_status
         substring(ptstatus,9,1) = "#".
      if can-find(isd_det where isd_status = ptstatus
         and isd_tr_type = "ADD-SO")
      then do:
         /* RESTRICTED PROCEDURE FOR ITEM STATUS CODE XXX */
         {pxmsg.i &MSGNUM=358 &ERRORLEVEL=3 &MSGARG1=pt_status}
         undo, retry.
      end.

      global_part = input scx_part.

      find ptp_det where ptp_part = pt_part and
         ptp_site = input scx_shipfrom no-lock no-error.

      if (available ptp_det and (ptp_pm_code = "C" or ptp_pm_code = "F"))
      then do:
         /* ITEM PUR/MFG CODE IS # */
         {pxmsg.i &MSGNUM=1850 &ERRORLEVEL=2 &MSGARG1=ptp_pm_code}
      end.
      else
      if (not available ptp_det
         and (pt_pm_code = "F" or pt_pm_code = "C"))
      then do:
         /* ITEM PUR/MFG CODE IS # */
         {pxmsg.i &MSGNUM=1850 &ERRORLEVEL=2 &MSGARG1=pt_pm_code}
      end.

      /* CHECK ITEM EXISTENCE IN REMOTE DB*/
      assign
         new_site = order-shipfrom
         global_part = pt_part.
      {gprun.i ""gpptsi01.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      if err_stat <> 0 then do:
         /* Item does not exist at this site */
         {pxmsg.i &MSGNUM=715 &ERRORLEVEL=3}
         undo, retry.
      end.

      find scx_ref where scx_type = 1
         and scx_shipfrom = order-shipfrom
         and scx_shipto   = l_scx_shipto
         and scx_part     = input frame sod scx_part
         and scx_custref  = input frame sod scx_custref
         and scx_modelyr  = input frame sod scx_modelyr
         and scx_po       = input frame sod scx_po
      no-lock no-error.

      if available scx_ref and scx_order <> so_nbr then do:
         /* Item & PO on another order for this ship-from/ship-to */
         /* More than one matching PO line item for this part */
         {pxmsg.i &MSGNUM=8286 &ERRORLEVEL=3}
         undo, retry.
      end.

      if not available scx_ref then do:
         /*!- LOGIC TO WRAP AROUND IF THE LINE# LIMIT IS REACHED
              AND TO SEEK ANY UNUSED LINE NUMBER. CODE COMPLEMENTS
              THE FUNCTIONALITY OF ARCHIVE/DELETE OF SCHEDULE LINE */
         find last sod_det where sod_nbr = so_nbr no-lock no-error.
         line = 1.
         /* SCREENS & REPORTS DON'T SUPPORT 4 DIGIT LINE NOS. */
         if available sod_det then do:
            if sod_line < 999 then
               line = sod_line + 1.
            else
               if sod_line = 999 then do:
               /*  MAX LINE# USED, SEARCH FOR NEXT AVAILABLE LINE# */
               {pxmsg.i &MSGNUM=6025 &ERRORLEVEL=1}
               pause 1 no-message.
               do counter = 1 to 999:
                  display counter @ scx_line.
                  if not can-find (scx_ref where scx_type = 1 and
                                   scx_order = so_nbr         and
                                   scx_line  = counter)
                  then do:
                     line = counter.
                     leave.
                  end.
               end.
               if counter = 1000 then do:
                  /* ALL AVAILABLE LINE# ARE USED */
                  {pxmsg.i &MSGNUM=6026 &ERRORLEVEL=4}
                  undo, retry.
               end.
            end.  /* if sod_line = 999  */
         end.  /* if available sod_det */

         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

         create scx_ref.
         assign
            scx_type     = 1
            scx_shipfrom = order-shipfrom
            scx_shipto   = l_scx_shipto
            scx_part       = input frame sod  scx_part   
            scx_po         = input frame sod  scx_po   
            scx_order    = so_nbr
            scx_custref  =  input frame sod scx_custref
            scx_modelyr  =  input frame sod scx_modelyr.
         if recid(scx_ref) = -1 then .

         /* IF USER ENTERED LINE NUMBER IT'S OK IF IT'S UNUSED */
         if scx_line entered and line <> input scx_line then do:
            newline = input scx_line.
            if not can-find (scx_ref where scx_type = 1 and
               scx_order = so_nbr and scx_line = newline) and
               not can-find (sod_det where sod_nbr = so_nbr
               and sod_line = newline)
            then
               line = newline.
         end.

         display line @ scx_line.

         assign scx_line = line.

         create sod_det.
         assign
            sod_nbr         = so_nbr
            sod_line        = scx_line
            sod_part        = scx_part
            sod_desc        = ""
            sod_site        = order-shipfrom
            sod_contr_id    = scx_po
            sod_sched       = yes
            sod_confirm     = yes
            sod_consignment = so_consignment
            sod_um          = pt_um
            sod_ord_mult    = 1
            sod_tax_in      = no
            sod_pst         = no
            sod_sched_chgd  = no
            sod_cum_date[1] = today
            sod_loc         = pt_loc
            sod_pr_list     = cm_pr_list
            sod_prodline    = pt_prod_line
            sod_custpart    = save_cust_part
            sod_custref     = input frame sod scx_custref
            sod_modelyr     = input frame sod scx_modelyr
            sod_fr_list     = so_fr_list
            sod_fr_wt_um    = pt_ship_wt_um
            sod_fr_wt       = pt_ship_wt.
         if recid(sod_det) = -1 then .

/*       SEE IF THERE IS A DEFAULT LOCATION FOR A  */
/*       CUSTOMER RESERVED LOCATION                */
         {gprun.i ""sorldft.p""
                  "(input so_ship,
                    input so_bill,
                    input so_cust,
                    input sod_site,
                    output cust-resv-loc,
                    output useloc)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if useloc = yes then sod_loc = cust-resv-loc.

         /* CONVERT PRICE FROM BASE TO ACCOUNT CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
                     "(input  base_curr,
                       input  so_curr,
                       input  so_ex_rate2,
                       input  so_ex_rate,
                       input  pt_price,
                       input  false,  /* DO NOT ROUND */
                       output sod_price,
                       output mc-error-number)" }
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.

         /* FIND THE SALES ORDER MASTER CONSIGNMENT RECORD */
         if using_cust_consignment then do:
            proc_id = "init".
            {gprunmo.i
               &program=""socnsod.p""
               &module="ACN"
               &param="""(input proc_id,
                 input so_nbr,
                 input sod_line,
                 input sod_part,
                 input so_ship,
                 input sod_site,
                 input yes)"""}

         end. /* IF using_cust_consignment */

         assign
            sod_list_pr   = sod_price
            sod_taxable   = so_taxable and pt_taxable
            sod_taxc      = pt_taxc
            sod_tax_usage = so_tax_usage
            sod_tax_in    = tax_in
            so_recno      = recid(so_mstr)
            sod_recno     = recid(sod_det)
            pt_recno      = recid(pt_mstr).

         {gprun.i ""soplsd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         yn = yes.
         /* Copy data from another order line for this item */
         {pxmsg.i &MSGNUM=8231 &ERRORLEVEL=1 &CONFIRM=yn}

         if yn then do:
            {gprun.i ""rcsomta.p"" "(input recid(sod_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         sod_sched_chg = no.
      end.
      else
         find sod_det where sod_nbr = scx_order
            and sod_line = scx_line exclusive-lock.

      display
         scx_part
         l_desc1    @ sod_desc
         pt_um     when (available pt_mstr)
         scx_po
         scx_custref
         scx_modelyr
         sod_custpart
         scx_line.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   /* DETAIL DATA ITEMS FRAME 1 */

   display
      sod_pr_list
      sod_price
      sod_list_pr
      sod_acct
      sod_sub
      sod_cc
      sod_dsc_acct
      sod_dsc_sub
      sod_dsc_cc
      sod_taxable
      sod_taxc
      sod_consume
      sod_type
      sod_loc
      sod_order_category
      sod_consignment when (using_cust_consignment)
   with frame sod1.

   {&RCSOMTB-P-TAG3}
   do with frame sod1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      ststatus = stline[2].
      status input ststatus.

      assign
         global_part = sod_part
         global_curr = so_curr.

      set
         sod_pr_list
         sod_list_pr
         sod_price
         sod_acct
         sod_sub
         sod_cc
         sod_dsc_acct
         sod_dsc_sub
         sod_dsc_cc
         sod_consume
         sod_type
         sod_loc
         sod_taxable
         sod_taxc
         sod_order_category
         sod_consignment when (using_cust_consignment)
         go-on("F5" "CTRL-D").

      if can-find (first pc_mstr
         where pc_list = input sod_pr_list
         and   pc_curr = so_curr
         and   pc_amt_type = "L" )
      then do:
         l_continue = yes.
         /* DISCOUNT LIST MUST BE TYPE D, M OR P. CONTINUE Y/N? */
         {pxmsg.i &MSGNUM=6229 &ERRORLEVEL=2 &CONFIRM=l_continue}
         if not l_continue then do:
            next-prompt sod_pr_list.
            undo, retry.
         end. /* IF NOT L_CONTINUE */
      end. /* IF CAN_FIND  */

   /* VALIDATE sod_order_category AGAINST GENERALIZED CODES */
      if sod_order_category <> "" then do:
         if not ({gpcode.v sod_order_category "line_category"}) then do:
            /* VALUE MUST EXIST IN GENERALIZED CODES */
            {pxmsg.i &MSGNUM=716 &ERRORLEVEL=3}
            next-prompt sod_order_category with frame sod1.
            undo, retry.
         end. /* IF NOT sod_order_category */
      end. /* IF sod_order_category <> "" */

      del-yn = no.
      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
      then do:
         del-yn = yes.
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if not del-yn then undo, retry.
      end.

      if del-yn then do:

         if can-find(first sch_mstr where sch_type = 1
            and sch_nbr = sod_nbr and sch_line = sod_line)
            or can-find(sch_mstr where sch_type = 1
            and sch_nbr = sod_nbr and sch_line = sod_line)
            or can-find(first sch_mstr where sch_type = 2
            and sch_nbr = sod_nbr and sch_line = sod_line)
            or can-find(sch_mstr where sch_type = 2
            and sch_nbr = sod_nbr and sch_line = sod_line)
            or can-find(first sch_mstr where sch_type = 3
            and sch_nbr = sod_nbr and sch_line = sod_line)
            or can-find(sch_mstr where sch_type = 3
            and sch_nbr = sod_nbr and sch_line = sod_line)
         then do:
            /* Cannot delete.  Schedule exists */
            {pxmsg.i &MSGNUM=6022 &ERRORLEVEL=3}
            undo, retry.
         end.

         if sod_qty_inv <> 0 then do:
            /* Outstanding qty to invoice, delete not allowed. */
            {pxmsg.i &MSGNUM=604 &ERRORLEVEL=3}
            undo, retry.
         end.

         assign
            l_conf_ship   = 0
            shipper_found = 0.

         {gprun.i ""rcsddelb.p"" "(input sod_nbr,
                                   input sod_line,
                                   input sod_site,
                                   output shipper_found,
                                   output save_abs,
                                   output l_conf_ship,
                                   output l_conf_shid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if shipper_found > 0 then do:
            /* # Shippers/Containers exists for order, including # */
            save_abs = substring(save_abs,2,20).
            {pxmsg.i &MSGNUM=1118 &ERRORLEVEL=3
                     &MSGARG1=shipper_found &MSGARG2=save_abs}
            undo, retry.
         end.

         /* IF ALL THE SHIPPERS FOR THE ORDER HAVE BEEN CONFIRMED AND  */
         /* INVOICE POSTED DISPLAY WARNING AND ALLOW TO DELETE ORDER   */
         else
         if l_conf_ship > 0
         then do:
            l_conf_shid = substring(l_conf_shid,2,20).
            /* # CONFIRMED SHIPPERS EXIST FOR ORDER, INCLUDING # */
            {pxmsg.i &MSGNUM=3314 &ERRORLEVEL=2
                     &MSGARG1=l_conf_ship &MSGARG2=l_conf_shid}
         end. /* IF L_CONF_SHIP > 0 */

         {gprun.i ""rcsddel.p"" "(input recid(sod_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* IF NO LINE ITEMS THEN LEAVE THIS PROGRAM SINCE THE HEADER
         WILL HAVE BEEN DELETED ALSO*/
         if not available so_mstr then leave.

         hide frame sod1.
         clear frame sod  no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame sod = F-sod-title.
         next detailloop.
      end.

      if sod_pr_list <> "" then do:
         sod_recno = recid(sod_det).
         pt_recno = recid(pt_mstr).

         find first pc_mstr where pc_list = sod_pr_list
            and pc_curr = so_curr
            and pc_prod_line = ""
            and pc_part = sod_part
            and pc_um = sod_um
         no-lock no-error.

         if soc_pl_req and not available pc_mstr then do:
            /* Required price list for Item # in UM # not found */
            {pxmsg.i &MSGNUM=689 &ERRORLEVEL=3
                     &MSGARG1=sod_part &MSGARG2=sod_um}
            undo, retry.
         end.

         if not available pc_mstr then do:
            /* Required price list for Item # in UM # not found */
            {pxmsg.i &MSGNUM=689 &ERRORLEVEL=2
                     &MSGARG1=sod_part &MSGARG2=sod_um}
         end.
      end.
      else do:
         if soc_pl_req then do:
            /* Required price list for Item # in UM # not found */
            {pxmsg.i &MSGNUM=689 &ERRORLEVEL=3
                     &MSGARG1=sod_part &MSGARG2=sod_um}
            undo, retry.
         end.
      end.

      if sod_list_pr <> pt_price then
      do:
         /* ITEM PRICE DOES NOT MATCH LIST PRICE */
         {pxmsg.i &MSGNUM=3322 &ERRORLEVEL=2}
      end. /* IF SOD_LIST_PR <> PT_PRICE */

      {gprunp.i "gpglvpl" "p" "initialize"}
      /* SET PROJECT VERIFICATION TO NO */
      {gprunp.i "gpglvpl" "p" "set_proj_ver" "(input false)"}
      {gprunp.i "gpglvpl" "p" "validate_fullcode"
         "(input  sod_acct,
           input  sod_sub,
           input  sod_cc,
           input  """",
           output valid_acct)"}
      /* sod_project WAS NOT USED IN ABOVE VALIDATION BECAUSE SCHEDULED
         ORDERS DOES NOT USE PROJECT CODES */

      if not valid_acct then do:
         next-prompt sod_acct with frame sod1.
         undo, retry.
      end.

      {gprunp.i "gpglvpl" "p" "initialize"}
      /* SET PROJECT VERIFICATION TO NO */
      {gprunp.i "gpglvpl" "p" "set_proj_ver" "(input false)"}
      {gprunp.i "gpglvpl" "p" "validate_fullcode"
         "(input  sod_dsc_acct,
           input  sod_dsc_sub,
           input  sod_dsc_cc,
           input  """",
           output valid_acct)"}
      /* sod_dsc_project WAS NOT USED IN ABOVE VALIDATION BECAUSE
         SCHEDULED ORDERS DOES NOT USE PROJECT CODES */

      if not valid_acct then do:
         next-prompt sod_dsc_acct with frame sod1.
         undo, retry.
      end.

      if so_curr <> base_curr then do:

         find ac_mstr where
            ac_code = sod_acct
         no-lock no-error.
         if available ac_mstr
            and ac_curr <> so_curr
            and ac_curr <> base_curr
         then do:
            /*ACCT CURR MUST BE TRANS OR BASE CURR*/
            {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
            next-prompt sod_acct with frame sod1.
            undo, retry.
         end. /* end of if available ac_mstr and ac_curr <> so_curr */

         find ac_mstr where
            ac_code = sod_dsc_acct
         no-lock no-error.
         if available ac_mstr
            and ac_curr <> so_curr
            and ac_curr <> base_curr
         then do:
            /*ACCT CURR MUST BE TRANS OR BASE CURR*/
            {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
            next-prompt sod_dsc_acct with frame sod1.
            undo, retry.
         end. /* end of if available ac_mstr and ac_curr <> so_curr */

      end. /* end of if so_curr <> base_curr                        */

      {gptxcval.i &code=sod_taxc &frame=sod1}

      /* GET TAX MANAGEMENT DATA */
      if sod_taxable then do:

         {gprun.i ""rcsomtc.p"" "(input recid(sod_det),
                                  input recid(so_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.

         {&RCSOMTB-P-TAG4}
      end.
      {&RCSOMTB-P-TAG6}

      if not sod_taxable and sod_tax_env = "" then
         sod_tax_env = so_tax_env.

      /* CREATE IMPORT EXPORT ied_det RECORDS */
      imp-okay = no.
      if can-find(first ie_mstr where ie_type = "1"
         and ie_nbr =  sod_nbr)
      then do:
         {gprun.i ""iedetcr.p""
            "(input ""1"",
              input sod_nbr,
              input sod_line,
              input recid(sod_det),
              input-output imp-okay)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if imp-okay = no  then undo , retry.
      end.

      hide frame sod1.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.

   assign
      sod_recno = recid(sod_det)
      so_recno  = recid(so_mstr)
      scx_recno = recid(scx_ref).

   /* UPDATE CONSIGNMENT RECORD */
   if using_cust_consignment then do:
      proc_id = "popup-update".
      {gprunmo.i
         &program=""socnsod.p""
         &module="ACN"
         &param="""(input proc_id,
           input sod_nbr,
           input string(sod_line),
           input sod_part,
           input so_ship,
           input sod_site,
           input yes)"""}

   end.  /* if using_cust_consignment */

   {gprun.i ""rcsomtd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


end.
{&RCSOMTB-P-TAG5}
